DECLARE num NUMBER;
BEGIN
SELECT COUNT(1) INTO num FROM USER_TABLES WHERE TABLE_NAME = UPPER('TB_AC_RULE') ;
IF num > 0 THEN
EXECUTE IMMEDIATE 'DROP TABLE TB_AC_RULE' ;
END IF;
END;
/

DECLARE
  C NUMBER;
BEGIN
SELECT COUNT(*) INTO C
FROM ALL_SEQUENCES
  WHERE SEQUENCE_NAME = 'SEQ_TB_AC_RULE_ID';
  IF (C > 0) THEN
    EXECUTE IMMEDIATE 'DROP SEQUENCE SEQ_TB_AC_RULE_ID';
END IF;
END
;
/
CREATE TABLE TB_AC_RULE
(
	id NUMBER(38) NOT NULL,
	from_client_id VARCHAR2(50) NOT NULL,
	to_client_id VARCHAR2(50) NOT NULL
);

COMMENT ON TABLE TB_AC_RULE IS '统一认证规则'
;

COMMENT ON COLUMN TB_AC_RULE.from_client_id IS '来源系统ID'
;

COMMENT ON COLUMN TB_AC_RULE.to_client_id IS '目标系统ID'
;

ALTER TABLE TB_AC_RULE
 ADD CONSTRAINT PK_TB_AC_RULE
  PRIMARY KEY (id) USING INDEX
;

CREATE SEQUENCE SEQ_TB_AC_RULE_ID
  INCREMENT BY 1
  START WITH 1
  NOMAXVALUE
  MINVALUE  1
  NOCYCLE
  NOCACHE
  NOORDER
;
CREATE OR REPLACE TRIGGER TRG_TB_AC_RULE_ID
  BEFORE INSERT
  ON TB_AC_RULE
  FOR EACH ROW
  BEGIN
    SELECT SEQ_TB_AC_RULE_ID.NEXTVAL
    INTO :NEW.ID
    FROM DUAL;
  END;
